package at.ac.tuwien.sepm.s2011.e0208329.dao;

import java.sql.SQLException;
//import java.util.Iterator;
//import java.util.Map;
//import java.util.Map.Entry;

import org.apache.log4j.Logger;

import at.ac.tuwien.sepm.s2011.e0208329.db.DatabaseManager;

public class OrderDAOImpl implements OrderDAO {// support the database-access for table "RechnungItem"
	
	private static final Logger log = Logger.getLogger(OrderDAOImpl.class);
	private DatabaseManager dm;
	
	public OrderDAOImpl() {
		this.dm = DatabaseManager.getDatabaseManager();// open the connection to my database

	}

	@Override
	public void storeSingleOrderItem(int billID, int serviceID, int number) throws SQLException { // insert a entry to the 
		//database's table "rechnungItem"
		String query = "INSERT INTO RechnungItem(fk_Rechnung, fk_Dienstleistung, Anzahl) VALUES("
				+ billID + "," + serviceID + "," + number + ")";
		log.debug(query);//output the SQL-Command as debug info
		dm.update(query);// run the method from DatabaseManager to perform the Update-Service

	}

	/**
	 * no need for next method, reuse the above method will do the same thing
	 */
//	public void storeAllOrderItems(int billID, Map<Integer, Integer> myItems) throws SQLException {
//		Iterator<Entry<Integer, Integer>> it = myItems.entrySet().iterator();
//	    while (it.hasNext()) {
//	        Map.Entry<Integer, Integer> pairs = (Map.Entry<Integer, Integer>) it.next();
//	        int serID = pairs.getKey().intValue();
//	        int number = pairs.getValue().intValue();
//	        storeSingleOrderItem(billID, serID, number);
//	    }
//		
//	}

}
